#include "stdafx.h"
/*
#include "PhysicsWorld.h"
#include "PhysicsEngine.h"

PhysicsWorld::PhysicsWorld() {
	// Example of how to init Havok's built-in memory management
	//http://www.ogre3d.org/forums/viewtopic.php?f=2&t=57205

	// The world cinfo contains global simulation parameters, including gravity, solver settings etc.
	hkpWorldCinfo worldInfo;
	// Set the simulation type of the world to multi-threaded.
	worldInfo.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED;

	// TODO Flag objects that fall "out of the world" to be automatically removed 
	// - just necessary for this physics scene
	worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_REMOVE_ENTITY;
	
	// TODO Set gravity to -11.0f
	worldInfo.m_gravity.set( 0,-9.8f,0);
	worldInfo.setBroadPhaseWorldSize( 2000.0f );
	worldInfo.setupSolverInfo( hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM );
	worldInfo.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_CONTINUOUS;

	m_havokWorld = new hkpWorld( worldInfo );

	// TODO Disable deactivation, so that you can view timers in the VDB. This should not be done in your game.
	m_havokWorld->m_wantDeactivation = false;

	// TODO When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks
	// to make sure only one thread is modifying the world at once to prevent multithreaded bugs. Each thread
	// must call markForRead / markForWrite before it modifies the world to enable these checks.
	m_havokWorld->markForWrite();

	// Register all collision agents, needed for more than box-to-box collisions
	// It's important to register collision agents before adding any entities to the world.
	hkpAgentRegisterUtil::registerAllAgents( m_havokWorld->getCollisionDispatcher() );
			
	// We need to register all modules we will be running multi-threaded with the job queue
	m_havokWorld->registerWithJobQueue( PhysicsEngine::getInstance()->getJobQueue() );

	PhysicsEngine::getInstance()->setupVisualDebugger(m_havokWorld);
}

PhysicsWorld::~PhysicsWorld() {*/
	/*
	m_havokWorld->markForWrite();
	m_havokWorld->removeReference();
	*/
/*
}

void PhysicsWorld::update(float deltaTime) {
	
	hkJobQueue* jobQueue = PhysicsEngine::getInstance()->getJobQueue();
	hkJobThreadPool* threadPool = PhysicsEngine::getInstance()->getThreadPool();

		hkStopwatch stopWatch;
	stopWatch.start();
	hkReal lastTime = stopWatch.getElapsedSeconds();

	hkReal timestep = 1.0f/60.0f;

	m_havokWorld->stepMultithreaded(jobQueue,threadPool,timestep);

	PhysicsEngine::getInstance()->stepVisualDebugger();

	hkMonitorStream::getInstance().reset();
	threadPool->clearTimerData();

	while(stopWatch.getElapsedSeconds()<lastTime+timestep);
	lastTime += timestep;
	//step the graphics display here

	// A stopwatch for waiting until the real time has passed
		
	//hkStopwatch stopWatch;
	//stopWatch.start();
	//hkReal lastTime = stopWatch.getElapsedSeconds();

	// <PHYSICS-ONLY>:
	// Step the physics world. This single call steps using this thread and all threads
	// in the threadPool. For other products you add jobs, call process all jobs and wait for completion.
	// See the multithreading chapter in the user guide for details
	*/		
	/*hkJobQueue* jobQueue = PhysicsEngine::getInstance()->getJobQueue();
	hkJobThreadPool* threadPool = PhysicsEngine::getInstance()->getThreadPool();
	//m_havokWorld->stepMultithreaded( jobQueue, threadPool, deltaTime );
	m_havokWorld->stepDeltaTime(deltaTime);
	//m_havokWorld->stepDeltaTime(deltaTime);

	// Step the visual debugger. We first synchronize the timer data

	// Clear accumulated timer data in this thread and all slave threads
	hkMonitorStream::getInstance().reset();
	threadPool->clearTimerData();*/
/*
}

void PhysicsWorld::setupWorld()
{

	//
	//  Create the ground box
	//
	{
		hkVector4 groundRadii( 70.0f, 2.0f, 140.0f );
		hkpConvexShape* shape = new hkpBoxShape( groundRadii , 0 );

		hkpRigidBodyCinfo ci;

		ci.m_shape = shape;
		ci.m_motionType = hkpMotion::MOTION_FIXED;
		ci.m_position = hkVector4( 0.0f, -2.0f, 0.0f );
		ci.m_qualityType = HK_COLLIDABLE_QUALITY_FIXED;

		m_havokWorld->addEntity( new hkpRigidBody( ci ) )->removeReference();
		shape->removeReference();
	}

	hkVector4 groundPos( 0.0f, 0.0f, 0.0f );
	hkVector4 posy = groundPos;

	//
	// Create the walls
	//

	//int wallHeight = 8;
	//int wallWidth  = 8;
	//int numWalls = 6;
	//hkVector4 boxSize( 1.0f, 0.5f, 0.5f);
	//hkpBoxShape* box = new hkpBoxShape( boxSize , 0 );
	//box->setRadius( 0.0f );

	//hkReal deltaZ = 25.0f;
	//posy(2) = -deltaZ * numWalls * 0.5f;

	//for ( int y = 0; y < numWalls; y ++ )			// first wall
	//{
		//createBrickWall( physicsWorld, wallHeight, wallWidth, posy, 0.2f, box, boxSize );
		//posy(2) += deltaZ;
	//}
	//box->removeReference();

	//
	// Create a ball moving towards the walls
	//

	




}
void PhysicsWorld::addEntity(hkpEntity* entity)
{
	m_havokWorld->lock();
	m_havokWorld->markForWrite();
	m_havokWorld->addEntity( entity );
	m_havokWorld->unmarkForWrite();
	m_havokWorld->unlock();

}*/